 package com.im.test.core;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.im.test.bean.FollowHostBean;
import com.im.test.bean.GiftBean;
import com.im.test.bean.GuardBean;
import com.im.test.bean.HostTaskBean;
import com.im.test.bean.ImMessageBean;
import com.im.test.bean.LiveRoomBean;
import com.im.test.bean.LiveRoomMessageBean;
import com.im.test.bean.LiveRoomTopRankBean;
import com.im.test.bean.NobleBean;
import com.im.test.bean.NormalMessageBean;
import com.im.test.bean.ParamBean;
import com.im.test.bean.RoomMessageBean;
import com.im.test.bean.SystemMessageBean;
import com.im.test.constant.BinaryCodeType;
import com.im.test.constant.WebSocketBaseRequestType;
import com.im.test.constant.WebSocketRequestType;
import com.im.test.util.ZipUtil;

import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.enums.ReadyState;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;

import java.io.UnsupportedEncodingException;
import java.net.SocketException;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@Slf4j
public class MyWebSocketClinet extends WebSocketClient {
    private Map<String, Object> pingData = new HashMap<>();
    private ScheduledFuture<?> pingTask;
    private long pingpongTime = 0;
    private boolean isClose = false;
    private boolean reconnect = false;
    private long times = 0;
    private long lastPong = 0;
    public MyWebSocketClinet(URI serverUri) {
        super(serverUri, new Draft_6455());
        this.setConnectionLostTimeout(-1);//关闭掉自动发送心跳
//        try {
//            this.getSocket().setReceiveBufferSize(10*1024*1024);
//        } catch (SocketException e) {
//            e.printStackTrace();
//        }
    }

    public void tryConnect(boolean reconnect) {
        this.reconnect = reconnect;
        if (getReadyState().equals(ReadyState.NOT_YET_CONNECTED)) {
            try {
                connect();
            } catch (IllegalStateException e) {
            }
        } else if (getReadyState().equals(ReadyState.CLOSING) || getReadyState().equals(ReadyState.CLOSED)) {
            reconnect();
        }
    }

    /**
     * @param actionId :消息ID
     * @param message  :消息内容
     * @param fanOut   :是否是广播模式
     */
    public void sendMessage(short actionId, String message, boolean fanOut) {
//        log.info("send actionId :" + actionId + " message  : " + message);
        try {
            message = message == null ? "" : message;
            //1.定制byte数组编码格式
            byte binaryCodeType = getBinaryCodeType(message, fanOut);
            //2.根据binaryCodeType 决定对消息体是否进行gizp压缩
            byte[] messageBody = getMessageBody(message, binaryCodeType);
//            printArray(messageBody);
            //3.获取消息header的长度
            int header = getByteHeaderLength();
            //4.创建需要通过IM通信的byte数组
            byte[] buffer = packageData(messageBody, header, binaryCodeType, actionId);
//            log.info( "需要发送的buffer 长度:" + buffer.length);
//            printArray(buffer);
            this.send(buffer);
//            log.info( "发送消息 id:" + actionId + "成功" + " codeType :" + binaryCodeType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void readMessage(ByteBuffer bytes) throws Exception {
        //1.读取无意义的默认占位消息头
        byte header = bytes.get();
        //2.获取actionId
        short actionId = bytes.getShort();
        //3.获取编码格式
        byte binaryCodeType = bytes.get();
        //4.获取消息体长度
        short messageBodySize = bytes.getShort();
//        log.info( "接收到的消息 id:" + actionId + " , binaryCodeType:" + binaryCodeType + " 长度:" + messageBodySize);
        byte[] bodyArr = new byte[messageBodySize];
        ImMessageBean imMessageBean = new ImMessageBean();
        imMessageBean.setActionId(actionId);
        bytes.get(bodyArr);
        if (actionId != WebSocketBaseRequestType.RequestAction.LOGIN_IN.getValue() && actionId != WebSocketBaseRequestType.RequestAction.LOGIN_OUT_COVER.getValue()) {
            String message = unPackageData(bodyArr, binaryCodeType);
            if (message == null) {
                log.error("IM消息错误");
            } else {
                imMessageBean.setMessage(message);
            }
//            log.info( "readMessage: message=" + message);
        }
        handler(imMessageBean);
    }
    
    private void handler(ImMessageBean beans){
        if (beans.getActionId() == WebSocketBaseRequestType.RequestAction.LOGIN_IN.getValue()) {
            reconnect = false;
            isClose = false;
            if (messageListener != null) {
                messageListener.onLogin();
            }
        } else if (beans.getActionId() == WebSocketBaseRequestType.RequestAction.PINGPONG.getValue()) {
            lastPong = Long.parseLong(beans.getMessage());
        } else if (beans.getActionId() == WebSocketBaseRequestType.RequestAction.LOGIN_OUT_COVER.getValue()) {
        } else {
            if(beans.getActionId()!=WebSocketRequestType.RequestAction.TOP_DEVOTE_LIST.getValue())
            System.out.println("收到消息:"+beans.getActionId());
//            switch (WebSocketRequestType.RequestAction.getEnum(beans.getActionId())) {
//                case MESSAGE:
//                    LiveRoomMessageBean bean = JSON.parseObject(beans.getMessage(), LiveRoomMessageBean.class);
//                    messageListener.onMessage(bean);
//                    break;
//                case ENTER:
//                    bean = JSON.parseObject(beans.getMessage(), LiveRoomMessageBean.class);
//                    messageListener.enter(bean);
//                    break;
//                case EXIT:
//                    break;
//                case ROOM_CHANGE:
//                    JSONArray jsonArray = JSONArray.parseArray(beans.getMessage());
//                    LiveRoomBean liveRoomBean = JSON.parseObject(jsonArray.getString(1), LiveRoomBean.class);
//                    messageListener.liveRoomTab(liveRoomBean, 0);
//                    break;
//                case KILL_USER:
//                    messageListener.killUser();
//                    break;
//                case REWARD:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    LiveRoomMessageBean liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setGiftBean(JSON.parseObject(jsonArray.getString(1), GiftBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.givingGift(liveRoomMessageBean);
//                    break;
//                case BUY_TASK:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setGiftBean(JSON.parseObject(jsonArray.getString(1), GiftBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.interactive(liveRoomMessageBean);
//                    break;
//                case BUY_LIVER_TASK:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setHostTaskBean(JSON.parseObject(jsonArray.getString(1), HostTaskBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.hostTask(liveRoomMessageBean);
//                    break;
//                case SET_MANAGE:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.setManage(jsonArray.getInteger(1), liveRoomMessageBean);
//                    break;
//                case MUTE:
//                    JSONArray jsonArrayMute = JSONArray.parseArray(beans.getMessage());
//                    messageListener.mute(jsonArrayMute.getInteger(1));
//                    break;
//                case GET_NEW_MESSAGE:
//                    messageListener.getNewMessage();
//                    break;
//                case TOP_DEVOTE_LIST:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    LiveRoomTopRankBean topRankBean = JSON.parseObject(jsonArray.getString(1), LiveRoomTopRankBean.class);
//                    messageListener.topRank(topRankBean);
//                    break;
//                case SYSTEM_MESSAGE:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = new LiveRoomMessageBean();
//                    liveRoomMessageBean.setSystemMessageBean(JSON.parseObject(jsonArray.getString(1), SystemMessageBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.onSystemMessage(liveRoomMessageBean);
//                    break;
//                case CLOSE_ROOM:
//                    messageListener.roomClose();
//                    break;
//                case BUY_VIP:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setNobleBean(JSON.parseObject(jsonArray.getString(1), NobleBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.openNoble(liveRoomMessageBean);
//                    break;
//                case GUARD_LEVEL:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setGuardBean(JSON.parseObject(jsonArray.getString(1), GuardBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.openGuard(liveRoomMessageBean);
//                    break;
//                case KILL_ROOM:
//                    messageListener.killRoom();
//                    break;
//                case ROOM_MESSAGE:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setRoomMessageBean(JSON.parseObject(jsonArray.getString(1), RoomMessageBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.roomMessage(liveRoomMessageBean);
//                    break;
//                case FOLLOW_LIVER:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setFollowHostBean(JSON.parseObject(jsonArray.getString(1), FollowHostBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.focusLiver(liveRoomMessageBean);
//                    break;
//                case BARRAGE_MSG:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    liveRoomMessageBean.setParamBean(JSON.parseObject(jsonArray.getString(3), ParamBean.class));
//                    messageListener.barrageMsg(liveRoomMessageBean);
//                    break;
//                case GLOBAL_GIFT:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setGiftBean(JSON.parseObject(jsonArray.getString(1), GiftBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    liveRoomMessageBean.setParamBean(JSON.parseObject(jsonArray.getString(3), ParamBean.class));
//                    messageListener.globalSystem(liveRoomMessageBean);
//                    break;
//                case GLOBAL_GAME:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    liveRoomMessageBean.setParamBean(JSON.parseObject(jsonArray.getString(3), ParamBean.class));
//                    messageListener.globalSystem(liveRoomMessageBean);
//                    break;
//                case GLOBAL_BUY_VIP:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setNobleBean(JSON.parseObject(jsonArray.getString(1), NobleBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    liveRoomMessageBean.setParamBean(JSON.parseObject(jsonArray.getString(3), ParamBean.class));
//                    messageListener.globalSystem(liveRoomMessageBean);
//                    break;
//                case GLOBAL_GUARD:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    liveRoomMessageBean.setGuardBean(JSON.parseObject(jsonArray.getString(1), GuardBean.class));
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    liveRoomMessageBean.setParamBean(JSON.parseObject(jsonArray.getString(3), ParamBean.class));
//                    messageListener.globalSystem(liveRoomMessageBean);
//                    break;
//                case CHANGE_NET:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = JSON.parseObject(jsonArray.getString(0), LiveRoomMessageBean.class);
//                    JSONArray jsonArrays = JSONArray.parseArray(jsonArray.getString(1));
//                    liveRoomMessageBean.setLineAddress(jsonArrays.getString(0));
//                    messageListener.switchLine(liveRoomMessageBean);
//                    break;
//                case KILL_MESSAGE:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = new LiveRoomMessageBean();
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.muteMessage(liveRoomMessageBean);
//                    break;
//                case MUTE_MESSAGE:
//                    jsonArray = JSONArray.parseArray(beans.getMessage());
//                    liveRoomMessageBean = new LiveRoomMessageBean();
//                    liveRoomMessageBean.setNormalMessageBean(JSON.parseObject(jsonArray.getString(2), NormalMessageBean.class));
//                    messageListener.muteMessage(liveRoomMessageBean);
//                    break;
//                default:
//            }
        }
    }

    private String unPackageData(byte[] body, byte binaryCodeType) throws Exception {
        byte[] bytes = body;
        if (binaryCodeType == BinaryCodeType.FANOUT_ZIP.getValue() || binaryCodeType == BinaryCodeType.NOMORL_ZIP.getValue()) {
            bytes = ZipUtil.gunzip(body);
        }
        String str = new String(bytes,"utf-8");
        return str;
    }

    @Override
    public void close() {
        super.close();
        isClose = true;

    }

    private void printArray(byte[] arr) {
        System.out.println("打印当前的message 长度为:" + arr.length);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " , ");
        }
        System.out.println();
    }

    /**
     * 组装消息.
     */
    private byte[] packageData(byte[] body, int headerLength, byte binaryCodeType, short actionId) {
        ByteBuffer buffer = ByteBuffer.allocate(body.length + headerLength);
        byte header = (byte) 128;
        buffer.put(header);//占位.默认消息头
        buffer.putShort(actionId);//保存actionId
        buffer.put(binaryCodeType);//保存编码格式
        buffer.putShort((short) body.length);//消息体长度
        buffer.put(body);//保存消息体
        buffer.flip();
        return buffer.array();
    }

    private byte[] getMessageBody(String message, short binaryCodeType) throws UnsupportedEncodingException {
        if (binaryCodeType == BinaryCodeType.FANOUT_ZIP.getValue() || binaryCodeType == BinaryCodeType.NOMORL_ZIP.getValue()) {
            //需要压缩
            return ZipUtil.gzip(message.getBytes());
        } else {
//            System.out.println("转码后的消息体:"+URLEncoder.encode(message,"UTF-8"));
//            return URLEncoder.encode(message, "UTF-8").getBytes();
            return message.getBytes("utf-8");
        }
    }

    /**
     * 获取固定数组头的长度。该数组作为消息头，描述信息如下:
     * 第一个字节为保留字节,第二个字节开始存放actionId占2个字节,
     * 第四个字节开始存放是binaryCodeType,占一个字节,第五个字节开始为消息正文长度,占2个字节.从第七个字节开始才是正文.
     * 所以消息头长度固定合计为1+2+1+2；
     */
    private int getByteHeaderLength() {
        return 1 + 2 + 1 + 2;
    }

    /**
     * 根据是否是广播消息以及消息体大小获取到二进制数组编码格式.
     * 普通消息:需要IM服务器进行解析：取值 0：该数据进行过zip压缩; 1:该数据没进行过zip压缩.
     * 广播消息 ：不需要IM服务器进行解析,并把该数据直接广播给其它用户；取值: 10：表示该数据进行过zip压缩, 11：表示该数据没进行过zip压缩
     */
    private byte getBinaryCodeType(String message, boolean fanOut) {
        if (message.length() >= 1000) {//数据大于1000字节才需要压缩,否则压缩率太低反而影响效率
            return fanOut ? BinaryCodeType.FANOUT_ZIP.getValue() : BinaryCodeType.NOMORL_ZIP.getValue();
        } else {
            return fanOut ? BinaryCodeType.FANOUT_UNZIP.getValue() : BinaryCodeType.NOMORL_UNZIP.getValue();
        }
    }


    /**
     * 定期发送心跳
     */
    private void pingPong() {
        this.pingTask = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
            if (this.isClosed()) {
                System.out.println("当前已经关闭,停止发送ping!");
                pingTask.cancel(true);
                return;
            }
            pingpongTime = System.currentTimeMillis();
            if (lastPong != 0 && pingpongTime - lastPong > 20000) {
                pingTask.cancel(true);
                close();
                if (messageListener != null) {
                    messageListener.reconnect();
                    tryConnect(true);
                }
                return;
            }
            pingData.put("timer", pingpongTime);
//            pingData.put("timer", "1619605653239");
//            this.sendPing();
            String message = JSON.toJSONString(pingData);
            this.sendMessage(WebSocketBaseRequestType.RequestAction.PINGPONG.getValue(), message, false);
        }, 2000, 10000, TimeUnit.MILLISECONDS);
    }

    @Override
    public void onOpen(ServerHandshake handshakedata) {
//        System.out.println("on open --- ");
        log.info("开启连接:{}",this);
        int receiveBufferSize = 0;
        int sendBufferSize = 0;
        try {
            receiveBufferSize = this.getSocket().getReceiveBufferSize();
            sendBufferSize = this.getSocket().getSendBufferSize();
        } catch (SocketException e) {
            e.printStackTrace();
        }
        System.out.println("receiveBufferSize------------->:"+receiveBufferSize+",sendBufferSize--------------->"+sendBufferSize);
        WebSocketMap.clinets.add(this);
        pingPong();
    }

    @Override
    public void onMessage(String message) {
        //接收String类型的message
//        log.info( "____on  ByteBuffer message --- " + message);
    }

    @Override
    public void onMessage(ByteBuffer bytes) {
        //接收byte类型的message,默认使用这个
//        log.info( "____on  ByteBuffer message --- " + bytes);
        try {
            readMessage(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
        this.pingTask.cancel(true);
        WebSocketMap.clinets.remove(this);
        log.info("关闭连接:{}",this);
//        log.info( "on close ---stop ping  remote="+remote+"code="+code+"reason="+reason);
    }

    @Override
    public void onError(Exception ex) {

        long currentTime = System.currentTimeMillis();
        if (currentTime - times < 2000) {
            return;
        }
        times = currentTime;
        if (reconnect) {
            try {
                Thread.sleep(2000);
                close();
//                    tryConnect(true)
                if (messageListener != null) {
                    messageListener.reconnect();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        tryConnect(true);
        log.info( "on error --- ==" + ex.toString());
    }

    public interface MessageListener {
        /**
         * 收到消息
         *
         * @param i
         */
        void onMessage(LiveRoomMessageBean i);

        /**
         * 系统消息
         *
         * @param i
         */
        void onSystemMessage(LiveRoomMessageBean i);

        /**
         * socket 登录成功
         */
        void onLogin();

        /**
         * 直播间关闭
         */
        void roomClose();

        /**
         * 用户进入房间
         */
        void enter(LiveRoomMessageBean i);

        /**
         * 禁言
         *
         * @param i 0=取消禁言，1=禁言
         */
        void mute(int i);

        /**
         * 收到新消息，显示红点
         */
        void getNewMessage();

        /**
         * 设置管理员
         *
         * @param i 0=取消，1=成为
         */
        void setManage(int i, LiveRoomMessageBean bean);

        /**
         * 提出直播间
         */
        void killUser();

        /**
         * 送礼
         */
        void givingGift(LiveRoomMessageBean bean);

        /**
         * 房间顶部数字与排行
         */
        void topRank(LiveRoomTopRankBean bean);

        /**
         * 切换房间类型
         *
         * @param bean
         * @param type 0=切换房间，1=判断权限
         */
        void liveRoomTab(LiveRoomBean bean, int type);

        /**
         * 开通贵族
         */
        void openNoble(LiveRoomMessageBean givingGiftUserBean);

        /**
         * 开通守护
         */
        void openGuard(LiveRoomMessageBean givingGiftUserBean);

        /**
         * 亲密互动
         */
        void interactive(LiveRoomMessageBean bean);

        /**
         * 转盘
         */
        void hostTask(LiveRoomMessageBean bean);

        /**
         * 超管关闭直播间
         */
        void killRoom();

        /**
         * 房间内系统消息
         *
         * @param bean
         */
        void roomMessage(LiveRoomMessageBean bean);

        /**
         * 弹幕
         * BARRAGE_MSG
         *
         * @param bean
         */
        void barrageMsg(LiveRoomMessageBean bean);

        /**
         * 关注主播
         *
         * @param bean
         */
        void focusLiver(LiveRoomMessageBean bean);

        /**
         * 开通守护全区通知
         *
         * @param bean
         */
        void globalSystem(LiveRoomMessageBean bean);

        /**
         * 切换路线
         *
         * @param bean
         */
        void switchLine(LiveRoomMessageBean bean);

        /**
         * 禁言消息
         *
         * @param bean
         */
        void muteMessage(LiveRoomMessageBean bean);

        /**
         * 重连
         */
        void reconnect();

        /**
         * 重连失败
         */
        void reconnectFail();
    }

    public MessageListener messageListener;

    public void setMessageListener(MessageListener messageListener) {
        this.messageListener = messageListener;
    }
}
